package com.spring.web.interceptor;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.spring.utils.Constants;
import com.sun.org.apache.bcel.internal.generic.GETSTATIC;

public class PreventReSubmitFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) resp;
		HttpSession session = request.getSession();
		String url = request.getServletPath();
		if(url.contains("_page") || url.contains("_list")){
			if(session.getAttribute(Constants.FORM_SUBMIT_SIGN) == null){
				session.setAttribute(Constants.FORM_SUBMIT_SIGN, Constants.FORM_SUBMIT_SIGN);
				System.out.println(session.getAttribute(Constants.FORM_SUBMIT_SIGN));
			}
		}
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}



}
